package com.ajax;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.sql.DAO;

public class ChaXunTiaoJian extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/xml;charset=UTF-8");
        response.setHeader("Cache-Control", "no-cache");
        response.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		int a = Integer.parseInt(request.getParameter("a"));
		
		for(int i = 1; i <= a; i++){
			out.print("<div class='form-group col-xs-12 section-top-10'>");
			out.print("<label>条件" + i + "：");
			out.print("<select id='xvanzechaxunkuang"+i+"' value='null' class='form-control' name='customers' vertical-align='middle' onchange='showchaxunkuang(this.value,"+i+")'>");
			DAO dao = new DAO();
			String sqlyujv = "cunkuanqvkuan";
			List<String> list = new ArrayList<String>();
			list = dao.getColumnNames(sqlyujv);
			out.print("<option class='form-control' id='null"+i+"' value='null'>--请选择查询条件--</option>");
			for(String lie : list){
				if(lie.equals("id")){}
				else if(lie.equals("name")){}
				else if(lie.equals("money")){
					out.print("<option class='form-group col-xs-12 section-top-10' class='form-control' id='" + lie + "' value='" + lie + "'>操作金额</option>");
				}
				else if(lie.equals("style")){
					out.print("<option class='form-control' id='" + lie + "' value='" + lie + "'>操作类型</option>");
				}
				else if(lie.equals("date")){
					out.print("<option class='form-control' id='" + lie + "' value='" + lie + "'>操作时间</option>");
				}
				else if(lie.equals("yue")){
					out.print("<option class='form-control' id='" + lie + "' value='" + lie + "'>账户余额</option>");
				}
			}
			out.print("</select>");
			
			out.print("请选择关系：");
			out.print("<select id='guanxi"+i+"' value='and' class='form-control' name='customers' vertical-align='middle'>");
			out.print("<option class='form-control' id='and' value='and'>and</option>");
			out.print("<option class='form-control' id='or' value='or'>or</option>");
			out.print("<option class='form-control' id='in' value='in'>in</option>");
			out.print("<option class='form-control' id='not' value='not'>not</option>");
			out.print("</select>");
			
			out.print("</label>");
				out.print("<div class='form-group col-xs-12 section-top-10' id='chaxunkuang" + i + "' vertical-align='middle'></div>");
			out.print("</div>");
			out.print("<br>");
		}
		
		out.flush();
		out.close();
	}

}
